"use strict";

function resolve(dir) {
  return path.join(__dirname, dir);
}

const path = require("path");

// 引入等比适配插件
const px2rem = require("postcss-px2rem");
// 配置基本大小
const postcssRem = px2rem({
  // 基准大小 baseSize，需要和changeRem.js中相同
  remUnit: 16,
});

module.exports = {
  devServer: {
    host: '0.0.0.0',
    hot: true,
    open: true,
    proxy: {
      '/api': {
        target: `http://localhost:8081`,
        changeOrigin: true,
        pathRewrite: {
          '^/api' : ''
        }
      },
    },
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [postcssRem],
      },
    },
  },
  chainWebpack(config) {
    // set svg-sprite-loader
    config.module.rule("svg").exclude.add(resolve("src/assets/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/assets/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      })
      .end();
  }
};
